package de.hwr.sudokuspielehr.ui.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import de.hwr.sudokuspielehr.data.Sudoku;
import de.hwr.sudokuspielehr.ui.UserInterface;

/**
 * 
 * @author J. Reischauer
 * 
 */
public class SolveButtonListener implements ActionListener {

	/**
	 * UserInterface instance.
	 */
	UserInterface ui;

	/**
	 * Constructor of solve button listener.
	 * 
	 * @param pUi
	 *            UserInterface instance
	 */
	public SolveButtonListener(UserInterface pUi) {
		ui = pUi;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (!ui.getSolutionDisplayed()) {
			ui.openSudoku(ui.getSudoku(), false, 1);
			ui.setSolutionDisplayed(true);
		} else {
			Sudoku s = ui.getSudoku();
			ui.openSudoku(s, false, 2);
			ui.setSolutionDisplayed(false);
		}
	}

}
